﻿namespace com.vs.General
{
    using com.vs.DataAccess;
    using com.vs.DataAccess.DO;
    using System;

    public class SessionFactory
    {
        public static Session CreateSession()
        {
            return new Session();
        }

        public static Session CreateSession(string stUser, string stConnString)
        {
            Session sess = null;
            DataHelper helper = null;
            UserDO modelByPK = null;
            Session session2;
            try
            {
                sess = new Session {
                    User = stUser,
                    ConnectionString = stConnString
                };
                modelByPK = UserDO.GetModelByPK(sess, stUser);
                if (modelByPK != null)
                {
                    sess.CurrentWarehouse = modelByPK.DEFAULT_WHS;
                }
                session2 = sess;
            }
            catch (Exception exception)
            {
                ExceptionManager.LogException(sess, exception);
                session2 = null;
            }
            finally
            {
                if (helper != null)
                {
                    helper.Dispose();
                }
            }
            return session2;
        }
    }
}

